<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    canvas {
      border: 2px solid red;
    }
  </style>
</head>
<body>
  <canvas height="300px" width="400px"></canvas>
</body>
<script>
  const canvas = document.querySelector('canvas')
  var context = canvas.getContext('2d');

  context.strokeStyle = "green"
  //起点
  context.moveTo(10,10)
  //其他点
  context.lineTo(110,110)
  context.lineTo(220,110)
  //闭合
  context.closePath()
  context.fillStyle="red"
  context.fill()

  context.strokeStyle="pink"
  context.lineWidth = "20"

  //画
  context.stroke()


</script>
</html>